num = input("введите четырехзначное число:")
if num.isdigit() and 1000 <= int(num) <= 9999:
    for i in range(len(num), 0, -1):
        p = int(num[:i])
        if p > 1:
            for j in range(2, int(p ** 0.5) + 1):
                if p % j == 0:
                    break
            else:
                print(p)
                break
    else:
        print(0)
else:
    print(0)
